import {
	toast
} from "./utils"

const URL_PREFIX = '/wx-api'

function request(url, method = 'GET', params) {
	return new Promise((resolve, reject) => {
		uni.request({
			url: URL_PREFIX + url,
			method: method,
			data: params,
			success: (e) => {
				let edata = e.data
				let {
					code,
					msg,
					data
				} = edata
				if (code == 200) {
					resolve(data)
				} else {
					toast(msg)
					reject(e)
				}
			}
		})
	})
}

export function requestGet(url, params) {
	return request(url, 'GET', params)
}

export function requestPost(url, params) {
	return request(url, 'POST', params)
}